import pandas as pd
from pyecharts import options as opts
from pyecharts.charts import Calendar
from pyecharts.globals import ThemeType
df = pd.read_excel('某地区2023年上半年空气质量指数.xlsx')
data=df[['日期','空气质量指数（AQI）']].values.tolist()
calendar=Calendar(init_opts=opts.InitOpts(
    theme=ThemeType.ESSOS,page_title='日历图'))
calendar.add(series_name='',yaxis_data=data,
             calendar_opts=opts.CalendarOpts(
                 range_=['2023-01-01','2023-06-30'])
             )
calendar.set_global_opts(
    title_opts=opts.TitleOpts(
        title='某地区2023年上半年空气质量指数日历图',
        pos_left='center'),
    legend_opts=opts.LegendOpts(is_show=False),
    visualmap_opts=opts.VisualMapOpts(
        orient='horizontal',
        is_piecewise=True,
        pos_top='45%',
        pos_left='center',
        pieces=[
            {'min':0,'max':50,'label':'优','color':'green'},
            {'min':51,'max':100,'label':'良','color':'yellow'},
            {'min':101,'max':150,'label':'轻度污染','color':'orange'},
            {'min':151,'max':200,'label':'中度污染','color':'red'},
            {'min':201,'max':300,'label':'重度污染','color':'purple'},
            {'min':301,'max': '严重污染','color':'brown'},
        ]
    )
)
calendar.render('例7-3.html')